

var moldSwjfDialog = {
	oThis: null,
	dialog: null,

	detail: null,
	isOk: false, // 是否确认

	init: function () {
		this.initState();
		this.initEvent();
	},

	initState: function () {
		this.oThis = $('#swjfDialog');
		this.oFooter = this.oThis.find('._footer');
		this.dialog = new TheDialog('#swjfDialog');
	},

	initEvent: function () {
		var _this = this;

		this.oThis.find('.step .item:eq(0) .icon').on('click', function () {
			var oItem = $(this).parent();
			if (_this.detail.physicalState == 0) {
				oItem.toggleClass('no');
				_this.isOk = !_this.isOk;
			}
		})

		this.oThis.find('.step .item:eq(1) .icon').on('click', function () {
			var oItem = $(this).parent();
			if (_this.detail.physicalState == 1) {
				oItem.toggleClass('no');
				_this.isOk = !_this.isOk;
			}
		})

		this.oThis.find('.submit-btn').on('click', function () {
			_this.submit();
		})
	},

	show: function (detail) {
		this.detail = detail;
		this.isOk = false;

		this.dialog.show();

		this.setDetailHtml();
	},

	// 提交
	submit: function () {
		var _this = this;

		if (!this.isOk) {
			var msg = '';
			if (this.detail.physicalState == 0) {
				msg = '请确认实物已发货';
			} else if (this.detail.physicalState == 1) {
				msg = '请确认实物已接收';
			}
			Qmsg.error(msg);
			return;
		}
		var param = {
			id: this.detail.id,
			state: this.detail.physicalState == 0 ? 1 : 2
		}
		$.ajax({
			type: 'get',
			url: pb.api + '/task/physical',
			data: param,
			success: function (res) {
				if (res.result == "true") {
					_this.dialog.close();
					Qmsg.success('实物交付状态修改成功');
					oPage.getData();
				} else {
					Qmsg.error(res.message);
				}
			}
		})
	},

	setDetailHtml: function () {
		var html = '';

		this.oThis.find('.sqdh-text').html(this.detail ? this.detail.applyNo : '-');
		this.oThis.find('.sqsj-text').html(this.detail ? this.detail.applyTime : '-');
		this.oThis.find('.sqks-text').html(this.detail ? this.detail.deptName : '-');
		this.oThis.find('.sqys-text').html(this.detail ? this.detail.doctorName : '-');
		this.oThis.find('.hzxm-text').html(this.detail ? this.detail.patientName : '-');
		this.oThis.find('.xb-text').html(this.detail ? this.detail.sex : '-');
		this.oThis.find('.nl-text').html(this.detail ? this.detail.age : '-');
		this.oThis.find('.dzbw-text').html(this.detail ? this.detail.partName : '-');
		this.oThis.find('.jcbw-text').html(this.detail ? this.detail.checkPointMethod : '-');
		this.oThis.find('.jmjh-text').html(this.detail ? this.detail.modePlanTime : '-');
		this.oThis.find('.zmjh-text').html(this.detail ? this.detail.makePlanTime : '-');

		if (this.detail.physicalState != 0) {
			this.oThis.find('.step .item:eq(0)').removeClass('no');
			this.oThis.find('.step .item:eq(0) p').html(this.detail.matterDeliverUserName + '</br>' + this.detail.matterDeliverTime);
		} else {
			this.oThis.find('.step .item:eq(0)').addClass('no');
			this.oThis.find('.step .item:eq(0) p').html('');
		}
		if (this.detail.physicalState == 2) {
			this.oThis.find('.step .item:eq(1)').removeClass('no');
			this.oThis.find('.step .item:eq(1) p').html(this.detail.matterReceiveUserName + '</br>' + this.detail.matterReceiveTime);
		} else {
			this.oThis.find('.step .item:eq(1)').addClass('no');
			this.oThis.find('.step .item:eq(1) p').html('');
		}
		
		if (this.detail.fileState != 2 || this.detail.physicalState == 2) {
			this.oFooter.hide();
		} else {
			this.oFooter.show();
		}
	}


}

$(function () {
	moldSwjfDialog.init();
})

